<?php

class PageListSmall{
	public 	$start;
	public 	$end;
	public 	$kezdooldal;
	public 	$pagecount;
	public	$firstrecord=0;
	private $o='';
	public	$entryperpage=30;
	
	function __construct($p){
		
		if(isset($p['entryperpage'])){
			$this->entryperpage=$p['entryperpage'];
		};	
		if(isset($p['offset'])){
			$this->kezdooldal=$p['offset'];
		}else
		if(isset($p['page'])){
			$this->kezdooldal=$p['page'];
		}else
		if(isset($_GET['page'])){
			$this->kezdooldal=$p['page'];
		}else
			$this->kezdooldal=0;
		if(isset($p['numrows'])){
			$this->pagecount=ceil($p['numrows']/$this->entryperpage);
		}else
		if(isset($p['pagecount'])){
			$this->pagecount=ceil($p['pagecount']);
		};
		$this->firstrecord=$this->kezdooldal*$this->entryperpage;
		$this->generate();		
	}
	
	function getLimit(){
		if($this->pagecount<2)return ' ';
		//limit offset, 
		return ' LIMIT '.($p['entryperpage']*$p['page']).','.$this->entryperpage.' ';	
	}
	
	function __destruct(){
		unset($this->o);
	}
	
	function __toString(){
		return $this->o;
	}
	
	function generate(){
		if($this->pagecount>1 ){		
			$p=$_GET;
			$p['page']='_pagenum_';		
			if(isset($p['noframe']))unset($p['noframe']);	
			$url=link_for(NULL,$p);
			
			if($this->start<0)$this->start=0;
			if($this->end>$this->pagecount)$this->end=$this->pagecount;
			$this->o.="<div class='pagelist'>";
			if($this->kezdooldal!=0)$ac='';else $ac='inactive';
				//elsÄ‚â€žĂ„â€¦Ä‚ËĂ˘â€šÂ¬Ă‚Â
				$this->o.= "<a href='".str_replace('_pagenum_',0,$url)."' ";
				if($ac)$this->o.=" onclick='return false;' ";
				$this->o.= " class='pagebutton".(($this->kezdooldal<2)?'_i':'').' '.$ac;
				$this->o.="' >&laquo;";
				$this->o.= "</a>";
			
			if($this->kezdooldal>0)$ac='';else $ac='inactive';
				//elÄ‚â€žĂ„â€¦Ä‚ËĂ˘â€šÂ¬Ă‚ÂzÄ‚â€žĂ„â€¦Ä‚ËĂ˘â€šÂ¬Ă‚Â
				$this->o.= "<a href='".str_replace('_pagenum_',($this->kezdooldal*1)-1,$url);
				$this->o.= "'  id='page_prev'  ";
				if($ac)$this->o.=" onclick='return false;' ";
				$this->o.= " class='pagebutton".(($this->kezdooldal<1	)?'_i':'').' '.$ac;
				$this->o.="' >&lsaquo;";
				$this->o.= "</a>";
			
			$text=($this->kezdooldal+1).'/'.$this->pagecount;
			$this->o.='<select dir="ltr" class="pagebutton_select" onchange=\'';

			$this->o.='var url="'.$url.'";url=url.replace(/_pagenum_/i,this.value);document.location.assign(url);';			
			$this->o.='\'>';
			
			$this->start=1;
			$this->end=$this->pagecount;			
			$offset=20000;			
			$this->start=$this->kezdooldal-$offset;
			if($this->start < 1){
				$this->start=1;
			};		
			
			if($this->start > 1){
				$this->o.='<option value="0">'.translate('first').'...</option>';
			};
			$this->end=$this->kezdooldal+$offset;
			if($this->end > $this->pagecount){
				$this->end=$this->pagecount;
			};
			if($this->end < $this->pagecount){
				$chopped=1;
			}else 
				$chopped=0;
				
			for($i=$this->start;$i<=$this->end;$i++){
				if($i!=($this->kezdooldal+1)){
					$this->o.='<option value="'.($i-1).'" >'.$i.'</option>';
				}else{
					$this->o.='<option value="'.($i-1).'" SELECTED>'.$i.'/'.$this->pagecount.'</option>';
				}
			}
			if($chopped)$this->o.='<option value="'.($this->pagecount-1).'">...'.translate('last').'</option>';
			
			$this->o.='</select>';
			
			
			if($this->kezdooldal<$this->pagecount-1)$ac='';else $ac='inactive';
				//kÄ‚â€žĂ˘â‚¬ĹˇÄ‚â€šĂ‚Â¶vetkezÄ‚â€žĂ„â€¦Ä‚ËĂ˘â€šÂ¬Ă‚Â
				$this->o.= "<a href='".str_replace('_pagenum_',(($this->kezdooldal*1)+1),$url);
				$this->o.= "'  id='page_next'  ";
				if($ac)$this->o.=" onclick='return false;' ";
				$this->o.= " class='pagebutton".(($this->kezdooldal>$this->pagecount-2)?'_i':'').' '.$ac;
				$this->o.="' >&rsaquo;";
				$this->o.= "</a>";
				
			if($this->kezdooldal<$this->pagecount-1)$ac='';else $ac='inactive';
				//utolsÄ‚â€žĂ˘â‚¬ĹˇĂ„Ä…Ă˘â‚¬Ĺˇ
				$this->o.= "<a href='".str_replace('_pagenum_',($this->pagecount*1)-1,$url);
				$this->o.= "'  id='page_last'  ";
				if($ac)$this->o.=" onclick='return false;' ";
				$this->o.= " class='pagebutton".(($this->kezdooldal>$this->pagecount-3)?'_i':'').' '.$ac;
				$this->o.="' >&raquo;";
				$this->o.= "</a>";
		
			$this->o.="</div>";
		};
	}






}
